package com.breaktian.demoapp.ui.jetpack.viewmodel;

import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;

import com.breaktian.network.api.finance.ApiCallback;
import com.breaktian.network.api.finance.ApiResult;

public class TestViewModel extends ViewModel {

    private MutableLiveData<Bean> beanLiveData = new MutableLiveData<>();
    private MutableLiveData<ApiResult.ApiError> errorLiveData = new MutableLiveData<>();

    public MutableLiveData<Bean> loadBean() {
        new TestApi().getBean("http://hbounty.com/test/api/get.php", new ApiCallback<Bean>() {
            @Override
            public void onResult(ApiResult<Bean> apiResult) {

            }

            @Override
            public void onSuccess(Bean data) {
                beanLiveData.postValue(data);
            }

            @Override
            public void onFail(ApiResult.ApiError apiError) {
                errorLiveData.postValue(apiError);
            }
        });
        return beanLiveData;
    }

    public MutableLiveData<Bean> getBean() {
        return beanLiveData;
    }

    public MutableLiveData<ApiResult.ApiError> getError(){
        return errorLiveData;
    }


    public static class Bean{
        public String title;
        public String desc;

    }

}



